class Admin::EventsController < ApplicationController
  layout 'admin/application'
  def index
    @events = Event.all
    respond_to do |format|
      format.html
      format.xml {render :xml => @event}
    end
  end
  
  def show
    @event = Event.find(params[:id])
    respond_to do |format|
      format.html
      format.xml { render :xml => @event}
    end
  end
  
  def new
    @event = Event.new
    respond_to do |format|
      format.html #admin/new.html.erb
      format.xml { render :xml => @evnet }
    end
  end
  
  def create
    @event = Event.new(params[:event])
     @event.point = Point.from_x_y(params[:pointx].to_f,params[:pointy].to_f)
     respond_to do |format|
       if @event.save
         format.html { redirect_to([:admin,@event], :notice => 'Event was successfully created !')}
       else
         format.html { render :action => "new"}
       end
     end
  end
  
  def edit
    @event = Event.find(params[:id])
    respond_to do |format|
      format.html
      format.xml {render :xml => @event}
    end
  end
  
  def update
    @event = Event.find(params[:id])
   @event.point = Point.from_x_y(params[:pointx].to_f,params[:pointy].to_f)
   respond_to do |format|
     if @event.update_attributes(params[:event])
       format.html { redirect_to([:admin, @event], :notice => 'Event was successfully created !')}
     else
       format.html { render :action => "edit"}
     end
   end
  end
  
  def destroy
    @event = Event.find(params[:id])
    @event.destroy
    respond_to do |format|
      format.html {redirect_to(admin_events_url)}
      format.xml { head:ok}
    end
  end
end
